<?php

namespace Es\Struct;


use Es\Constant\DocumentConst;
use Es\Exceptions\CommonExceptions;

class DocumentBulkStruct
{
    public  $index;
    public  $type;
    public  $ids;
    public  $body;
    //分批执行的条数
    public  $bulkNum;
    //为空则不指定_id由es默认生成
    public  $bulkIdFields;

    /**
     * @throws CommonExceptions
     */
    public function __construct(
        string $index, 
        array $body = [],
        array $ids = [],  
        string $type = '_doc',  
        int $bulkNum = DocumentConst::BULK_NUM_MAX,
        string $bulkIdFields = ''
    )
    {
        $this->index   = $index;
        $this->type    = $type;
        $this->ids     = $ids;
        $this->body    = $body;
        if( $bulkNum < DocumentConst::BULK_NUM_MIN || $bulkNum > DocumentConst::BULK_NUM_MAX){
            throw new CommonExceptions(CommonExceptions::BLUK_NUM_ERROR);
        }
        $this->bulkNum = $bulkNum;
        $this->bulkIdFields = $bulkIdFields;
    }
}